package com.wuge.gulimall.oms.interceptor;

import com.wuge.common.to.MemberTo;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserInterceptor implements HandlerInterceptor {
    public static ThreadLocal<MemberTo> loginUser=new ThreadLocal<>();
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String uri = request.getRequestURI();
        AntPathMatcher antPathMatcher = new AntPathMatcher();
        boolean match = antPathMatcher.match("/oms/order/status/**", uri);
        boolean match1 = antPathMatcher.match("/payed/notify", uri);

        if (match||match1){
            return true;
        }
        Object login = request.getSession().getAttribute("loginUser");
        if (login==null){
            request.getSession().setAttribute("msg", "请先进行登录");
             response.sendRedirect("http://auth.gulimall.com/login.html");
            return false;
        }
   else{
     loginUser.set((MemberTo) login);
     return true;
        }

    }
}
